# Contributor: Konstantin Kulikov <k.kulikov2@gmail.com>
# Maintainer: Konstantin Kulikov <k.kulikov2@gmail.com>
pkgname=grafana-image-renderer
pkgver=3.4.2
pkgrel=0
pkgdesc="Grafana Backend Plugin that handles rendering of panels & dashboards to PNGs using headless chrome"
url="https://github.com/grafana/grafana-image-renderer"
arch="x86_64" # Requires chromium, aarch64 and armv7 doesn't build because of grpc.
license="Apache-2.0"
makedepends="yarn"
depends="nodejs ttf-opensans chromium ca-certificates"
options="!check" # Has no test suite.
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/grafana/grafana-image-renderer/archive/v$pkgver.tar.gz
	$pkgname.initd $pkgname.confd $pkgname.json"

build() {
	export CHROME_BIN="/usr/bin/chromium-browser"
	export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

	# Don't pollute our aports repo with husky git hooks.
	# This command also acts as implicit "yarn install".
	yarn remove --pure-lockfile --ignore-engines -W husky

	# Wants nodejs 13, but alpine ships 14, ignore this requirement.
	yarn --ignore-engines build
}

package() {
	install -Dm755 "$srcdir/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.confd" "$pkgdir/etc/conf.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.json" "$pkgdir/etc/$pkgname.json"
	install -dm755 "$pkgdir/usr/share/$pkgname"
	cp -r "$builddir/node_modules" "$builddir/build" "$builddir/proto" "$pkgdir/usr/share/$pkgname/"
}

sha512sums="
95757e89fc84fdd0f5b2efa0f9230a69dc91ccf9892ddb5c6db1bf2d1c1fd9b8b317938b59e88ddb37af9c80a6493e3215dcb3ce3a8b1fb8cdac709a6abafbd7  grafana-image-renderer-3.4.2.tar.gz
06faad0f5abecf434c014ca91dccf3f07f18d96a8f526c3c1d2384cba8db44db5fe2b2165d8fc12a8fe8d121135077b0c70158ee29ebb1bfba8dd2a3110b349c  grafana-image-renderer.initd
88a119ad18fbde490ab9213487ae16b8aeeb65437275a1112f7423fa581a7470e6fb68654c2fd439afa68c0333aeefd0711f3fffd53615fa51d0702c80ed1c1b  grafana-image-renderer.confd
2ce48b9ea1da4ce5a16da5acb3fd801480d297ab2c39848020a99dd285640e003eb0d1c26b407f06ef5ad0ff2968b5ae71f56c26870346e6ad86e1f70df4cb78  grafana-image-renderer.json
"
